class LastOrderState(object):
  def __init__(self, timestamp_stickiness, price_stickiness):
    self._last_timestamp_stickiness = timestamp_stickiness
    self._last_price_stickiness = price_stickiness
    self._last_sell_timestamp = None
    self._last_buy_timestamp = None
    self._last_sell_price = None
    self._last_buy_price = None

  def _is_sell_last_order_far(self, timestamp, price, update_state=False):
    timestamp_different = (
        self._last_sell_timestamp is None
        or abs(self._last_sell_timestamp - timestamp) > self._last_timestamp_stickiness)
    price_different = (self._last_sell_price is None
                       or abs(self._last_sell_price - price) > self._last_price_stickiness)
    if (timestamp_different or price_different):
      if update_state:
        self._last_sell_timestamp = timestamp
        self._last_sell_price = price
      return True
    else:
      return False

  def _is_buy_last_order_far(self, timestamp, price, update_state=False):
    timestamp_different = (
        self._last_buy_timestamp is None
        or abs(self._last_buy_timestamp - timestamp) > self._last_timestamp_stickiness)
    price_different = (self._last_buy_price is None
                       or abs(self._last_buy_price - price) > self._last_price_stickiness)
    if (timestamp_different or price_different):
      if update_state:
        self._last_buy_timestamp = timestamp
        self._last_buy_price = price
      return True
    else:
      return False
